from pyspark.context import SparkContext, SparkConf
from pyspark.sql import HiveContext
import sys
sparkconf = SparkConf().setAppName("liz_pred").set("spark.ui.showConsoleProgress", "false")
sc = SparkContext(conf=sparkconf)
spark = HiveContext(sc)
sc.setLogLevel('ERROR')
hiveCtx = HiveContext(sc)

# db = 'liz'
# in_tb = sys.argv[1]
# hiveCtx.sql("use {db}".format(db=db))
# df_tmp = hiveCtx.sql("select * from {in_tb}".format(in_tb=in_tb))


db = 'liz'
hiveCtx.sql("use {db}".format(db=db))
# in_tb = sys.argv[1]
in_tb = 'fly_gid4m'
dataframe = spark.read.parquet("hdfs://getui-bi-ds/user/hive/warehouse/liz.db/{in_tb}".format(in_tb=in_tb))
dataframe.write.saveAsTable(in_tb, None, "overwrite", None)
